package com.yike.user.service.impl;

import com.yike.user.entity.ShopUser;
import com.yike.user.mapper.ShopUserMapper;
import com.yike.user.service.ShopUserService;
import com.yike.user.param.ShopUserPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 店铺用户表 服务实现类
 *
 * @author Sakura
 * @since 2024-08-26
 */
@Slf4j
@Service
public class ShopUserServiceImpl extends BaseServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {

    @Autowired
    private ShopUserMapper shopUserMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveShopUser(ShopUser shopUser) throws Exception {
        return super.save(shopUser);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateShopUser(ShopUser shopUser) throws Exception {
        return super.updateById(shopUser);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteShopUser(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<ShopUser> getShopUserPageList(ShopUserPageParam shopUserPageParam) throws Exception {
        Page<ShopUser> page = new PageInfo<>(shopUserPageParam, OrderItem.desc(getLambdaColumn(ShopUser::getCreateTime)));
        LambdaQueryWrapper<ShopUser> wrapper = new LambdaQueryWrapper<>();
        IPage<ShopUser> iPage = shopUserMapper.selectPage(page, wrapper);
        return new Paging<ShopUser>(iPage);
    }

}
